package com.sunni.controller;

import com.sunni.cofig.SpringCofiguration;
import com.sunni.service.UserService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.sql.DataSource;

public class UserController {


    @Test
    public void testSsmByXmlAndAnno(){
        ApplicationContext app = new ClassPathXmlApplicationContext("applicationContext.xml");
        UserService userService = app.getBean(UserService.class);
        userService.save();
        ((ClassPathXmlApplicationContext) app).close();
    }

    @Test
    public void testSsmByAnno(){
        ApplicationContext app = new AnnotationConfigApplicationContext(SpringCofiguration.class); // 加载spring注解核心类
        UserService userService = app.getBean(UserService.class);
        DataSource dataSource = (DataSource) app.getBean("dataSource");
        userService.save();
        ((AnnotationConfigApplicationContext) app).close();
    }
}
